/*
 * Copyright (C) 2009  Nepala Esperanto-Asocio, http://www.esperanto.org.np/
 * Author: Jacob Nordfalk
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

/*
 * ConversionPanelDevelopment.java
 *
 * Created on Feb 11, 2009, 9:58:34 AM
 */

package np.esperanto.conv4.ui;

import java.awt.Font;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import np.esperanto.conv4.font2unicode.Font2UnicodeMapping;
import np.esperanto.conv4.font2unicode.Font2UnicodeMappingFactory;

/**
 *
 * @author j
 */
public class ConversionPanelDevelopment extends ConversionPanel {

    /** Creates new form ConversionPanelDevelopment */
    public ConversionPanelDevelopment() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jButtonTestMappingFile = new javax.swing.JButton();
    jTextField1 = new javax.swing.JTextField();
    jLabel1 = new javax.swing.JLabel();
    jButton1 = new javax.swing.JButton();
    jComboBoxFonts = new javax.swing.JComboBox();
    jButton2 = new javax.swing.JButton();

    jButtonTestMappingFile.setText("Test mapping file...");
    jButtonTestMappingFile.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButtonTestMappingFileActionPerformed(evt);
      }
    });

    jTextField1.setText("Himalaya");

    jLabel1.setText("Font name: ");

    jButton1.setText("Scan for all fonts");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });

    jComboBoxFonts.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
    jComboBoxFonts.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jComboBoxFontsActionPerformed(evt);
      }
    });

    jButton2.setText("Print font info");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton2ActionPerformed(evt);
      }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(jComboBoxFonts, 0, 376, Short.MAX_VALUE)
          .addComponent(jButton1)
          .addGroup(layout.createSequentialGroup()
            .addComponent(jLabel1)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE))
          .addComponent(jButton2)
          .addComponent(jButtonTestMappingFile))
        .addContainerGap())
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(jButton1)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jComboBoxFonts, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jButton2)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 47, Short.MAX_VALUE)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel1)
          .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jButtonTestMappingFile)
        .addGap(61, 61, 61))
    );
  }// </editor-fold>//GEN-END:initComponents

    private void jButtonTestMappingFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonTestMappingFileActionPerformed
        try {
            // TODO add your handling code here:
            Font2UnicodeMappingFactory fac=new Font2UnicodeMappingFactory();
            Font2UnicodeMapping f2u = fac.getMapping(jTextField1.getText().toLowerCase());

            Font font = (Font) jComboBoxFonts.getSelectedItem();
            f2u.checkConsistency(font);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }//GEN-LAST:event_jButtonTestMappingFileActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        java.awt.GraphicsEnvironment ge = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment();
        Font[] fa = ge.getAllFonts();
        jComboBoxFonts.setModel(new DefaultComboBoxModel(fa));
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        Font f = (Font) jComboBoxFonts.getSelectedItem();
        System.err.println("f.getNumGlyphs() = " + f.getNumGlyphs());
        int num = f.getNumGlyphs();
        if (num<255) num=256*256-1; //255;
        for (int i=33; i<num; i++) {
            if (f.canDisplay(i))
               System.err.println("i = " + i+" \\u"+Integer.toHexString(i)+"   "+(char) i);
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jComboBoxFontsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxFontsActionPerformed
        // TODO add your handling code here:
        Font f = (Font) jComboBoxFonts.getSelectedItem();
        System.err.println("f = " + f);
        jTextField1.setText(f.getFontName());
    }//GEN-LAST:event_jComboBoxFontsActionPerformed


  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton jButton1;
  private javax.swing.JButton jButton2;
  private javax.swing.JButton jButtonTestMappingFile;
  private javax.swing.JComboBox jComboBoxFonts;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JTextField jTextField1;
  // End of variables declaration//GEN-END:variables

}
